<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>字典管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			
			$("#sort").val("10");
			
		});
		
		function initPtypes(obj)
		{
			var type = $(obj).find("option:selected").attr("type");
			var value = $(obj).val();
			$("#ptype").val(type);
			// 当父级字典为根目录时，字典类型需手动填写
			if("root" == type)
			{
				$("#type").val("");
				$("#ptypes").val("root");
				$("#type").attr("readonly",false);
				$("#tip").hide();
			}
			// 当父级字典为非根目录时，字典类型自动生成
			else
			{
				$("#type").val(type+"_"+value.split("~")[1]);
				$("#type").attr("readonly",true);
				var ptypes = $(obj).find("option:selected").attr("ptypes");
				$("#ptypes").val(ptypes);
				$("#tip").show();
			}
			
			
		}
	</script>
	
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/mdict/">字典列表</a></li>
		<li class="active"><a href="${ctx}/sys/mdict/form?id=${mdict.id}">字典<shiro:hasPermission name="sys:mdict:edit">${not empty mdict.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:mdict:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="mdict" action="${ctx}/sys/mdict/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">字典类型：</label>
			<div class="controls">
				<form:input id="type" path="type" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> <span id="tip">当父级字典类型不是“根类型”时，字典类型为该父级类型的字典类型+“_”+该父级字典类型的字典值</span></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">父级字典类型：</label>
			<div class="controls">
				<form:select path="" class="input-xlarge required" onchange="initPtypes(this);">
					<form:option value="root" type="root" label="根类型"/>
					<%-- <form:options items="${fns:getDictList('del_flag')}" itemLabel="label" itemValue="value" htmlEscape="false"/> --%>
				
					<c:forEach items="${mdicts }" var="mdict">
						<form:option type="${mdict.type }" value="${mdict.type }~${mdict.value }" ptypes="${mdict.ptypes },${mdict.type }" label="${mdict.name }"/>
					</c:forEach>
				
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<!-- <div class="control-group">
			<label class="control-label">所有父级字典类型：</label>
			<div class="controls"> -->
				<%-- <form:text path="ptypes" htmlEscape="false" maxlength="2000" placeholder="12" class="input-xlarge "/> --%>
			<!-- </div>
		</div> -->
		<input type="hidden" id="ptype" name ="ptype" value="root"/>
		<input type="hidden" id="ptypes" name ="ptypes" value="root"/>
		
		<div class="control-group">
			<label class="control-label">字典值：</label>
			<div class="controls">
				<form:input path="value" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">字典名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="100" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">排序：</label>
			<div class="controls">
				<form:input path="sort" id="sort" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">描述：</label>
			<div class="controls">
				<form:input path="description" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:mdict:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>

</html>